// "Copyright [2021] <Copyright Shengkai Lin>"

#include "resource_scheduler.h"

namespace ai_sim {
Define_Module(ResourceScheduler)
void ResourceScheduler::initialize() {
    EV << "Extracting workers topo" << std::endl;
    cModule * topo_module = getModuleByPath("^.topo_manager");
    topos = omnetpp::check_and_cast<TopoManager *> (topo_module);
    algotype = GpuScheduleAlgo(par("GpuScheduleAlgo").intValue());
    EV_INFO << "INIT ResourceScheduler FINISHED" << endl;
}

void ResourceScheduler::alloc_gpu_resource(
    taskboard& tmp_taskboard) {
    Enter_Method_Silent();
//////////////// Allocate gpu resources/////////////////////
    GpuScheduleAlgorithm* algo = GpuScheduleAlgorithm::get(algotype);
    int job_num = par("job_num");
    algo->scheduleGpu(tmp_taskboard, topos, job_num);
    // for (auto gpu : tmp_taskboard.used_gpus) {
    //     std::cout << "using gpu" << gpu->getModule()->getFullPath() << endl;
    // }
    // error("Stop");
    EV_INFO << "Finished alloc gpu resources" << std::endl;
}

}